//
//  XuanTaiData.m
//  BigTyre
//
//  Created by 💋索少杰 on 2017/3/21.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "XuanTaiData.h"
#import <AFNetworking.h>
#import "SelectTyreModel.h"
#define Url @"http://lscy4.caeac.com.cn/api/product_fenlei.php?appkey=1138"
//静态标示符
static XuanTaiData*data=nil;
@implementation XuanTaiData
//单利
+(instancetype)shardData{
    static dispatch_once_t oneKen;
    _dispatch_once(&oneKen, ^{
        
        data=[[XuanTaiData alloc]init];
    });
    return data;
}
+(instancetype)allocWithZone:(struct _NSZone *)zone{
    if (!data) {
        data = [super allocWithZone:zone];
    }
    return data;
}
-(id)copy{
    return self;
}
-(id)mutableCopy{
    return self;
}
//数据请求
-(void)getUrlRequest{
    
    AFHTTPSessionManager*manager=[AFHTTPSessionManager manager];
    manager.responseSerializer=[AFJSONResponseSerializer serializer];
    [manager GET:Url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        NSMutableSet *set = [NSMutableSet setWithArray:[manager.responseSerializer.acceptableContentTypes allObjects]];
        [set addObject:@"text/html"];
        manager.responseSerializer.acceptableContentTypes = set;
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        arrData=[[NSMutableArray alloc]init];
        
        NSArray *arr = (NSArray *)responseObject;
        for (NSDictionary *dic in arr) {
            SelectTyreModel*model=[[SelectTyreModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [arrData addObject:model];
            
        }
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"suo" object:arrData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"111");
    }];
}

@end
